define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'withdrawlapply/index' + location.search,
                    add_url: 'withdrawlapply/add',
                    edit_url: 'withdrawlapply/edit',
                    del_url: 'withdrawlapply/del',
                    multi_url: 'withdrawlapply/multi',
                    import_url: 'withdrawlapply/import',
                    table: 'withdrawlapply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'apply_id',
                sortName: 'apply_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'apply_id', title: __('Apply_id')},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'total_money', title: __('Total_money'), operate:'BETWEEN'},
                        {field: 'service_money', title: __('Service_money'), operate:'BETWEEN'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'state', title: __('State'), searchList: {"0":__('审核中'),"1":__('State 1'),"2":__('State 2')}, formatter: Table.api.formatter.normal},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                                                {
                            field: 'buttons',
                            width: "120px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                
                                {
                                    name: 'list',
                                    text: '通过',
                                    title: '通过',
                                    classname: 'btn btn-xs btn-success  btn-ajax',
                                    url: 'withdrawlapply/agree',
                                    visible: function (row) {
                                        // 判断当前行数据中的 status 字段的值是否等于 1
                                        if (row.state == '0') {
                                            // return true 代表显示
                                            return true;
                                        }
                                    },
                                    callback: function (data) {
                                        // Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                        location.reload();
                                    },
                                    success: function (data,rest) {
                                        var opt = {
                                            url: '',
                                        };
                                        //刷新table表单
                                        table.bootstrapTable('refresh', opt);
                                        return true;
                                    }
                                },
                                {
                                    name: 'list',
                                    text: '驳回',
                                    title: '驳回',
                                    classname: 'btn btn-xs btn-warning  btn-ajax',
                                    url: 'withdrawlapply/refuse',
                                    visible: function (row) {
                                        // 判断当前行数据中的 status 字段的值是否等于 1
                                        if (row.state == '0' ) {
                                            // return true 代表显示
                                            return true;
                                        }
                                    },
                                    callback: function (data) {
                                        // Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                        location.reload();
                                    },
                                    success: function (data,rest) {
                                        var opt = {
                                            url: '',
                                        };
                                        //刷新table表单
                                        table.bootstrapTable('refresh', opt);
                                        return true;
                                    }
                                },
                                
                                
                            ],
                            formatter: Table.api.formatter.buttons
                        },

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
